<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button type="info" icon="el-icon-refresh" @click="refresh"></el-button>
				<el-button type="primary" icon="el-icon-plus" @click="add"></el-button>
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="输入url检索" clearable></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" stripe>
				<el-table-column label="ID" prop="id" width="180" align="center"></el-table-column>
                <el-table-column label="Api Url" prop="api_url" align="left">

                </el-table-column>

                <el-table-column label="请求" prop="methods" width="180" align="center">
						<template #default="scope">
							<el-tag v-if="scope.row.methods == 1">GET</el-tag>
							<el-tag v-if="scope.row.methods == 2">POST</el-tag>
						</template>
				</el-table-column>
				<el-table-column label="类型" prop="type" width="180" align="center">
						<template #default="scope">
							<el-tag v-if="scope.row.type == 0">Api获取数据</el-tag>
							<el-tag v-if="scope.row.type == 1">Api提交数据</el-tag>
						</template>
				</el-table-column>
				<el-table-column label="关联模块" prop="method" width="380" align="center">
						<template #default="scope">
							<el-tag v-for="(item,index) in scope.row.modules_str" :key="index" type="success" style="margin-right: 6px;">{{item}}</el-tag>
						</template>
				</el-table-column>
				<el-table-column label="备注" prop="remarks" width="180" align="center"></el-table-column>
				<el-table-column label="操作" fixed="right" align="center" width="260">
					<template #default="scope">

                        <el-button-group>

                        	<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
                        		<template #reference>
                        			<el-button text type="primary" size="small">删除</el-button>
                        		</template>
                        	</el-popconfirm>
							<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
                        </el-button-group>

					</template>
				</el-table-column>

			</scTable>
		</el-main>
	</el-container>
	<savecat-dialog v-if="dialog.save" ref="savecatDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></savecat-dialog>
</template>

<script>
	import savecatDialog from './pagemodulesave'
	export default {
		name: 'module',
		components: {
			savecatDialog
		},
		data() {
			return {
				dialog: {
					save: false
				},
				apiObj: this.$API.system.module.page,
				selection: [],
				search: {
					keyword: null
				}
			}
		},
		methods: {
			//添加
			add(){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.savecatDialog.open()
				})
			},
			//编辑
			table_edit(row){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.savecatDialog.open('edit').setData(row)
				})
			},

			//删除
			async table_del(row){
				var reqData = {id: row.id,'act':'del'}
				var res = await this.$API.system.universal.handle.post(reqData,'/system/pagemodule_del');
				if(res.code == 200){
					this.$refs.table.refresh()
					this.$message.success("删除成功")
				}else{
					this.$alert(res.message, "提示", {type: 'error'})
				}
			},

			//表格选择后回调事件
			selectionChange(selection){
				this.selection = selection;
			},
			//搜索
			upsearch(){
				this.$refs.table.upData(this.search)
			},
            refresh(){
                this.$refs.table.reload()
            },
			//本地更新数据
			handleSaveSuccess(data, mode){
				console.log(mode,"sssssssssssssss")
				if(mode=='add'){
					this.$refs.table.reload()
				}else if(mode=='edit'){
					this.$refs.table.reload()
				}
			}
		}
	}
</script>

<style>
.red{
    font-size: 15px;
    color:#ff3333
}
</style>

